package com.definesys.smecrailtransit.module.lineCharts;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.base.SmecBaseFragment;
import com.definesys.smecrailtransit.databinding.ActivityLineChartsBinding;
import com.definesys.smecrailtransit.module.lineCharts.Fragment.DayChartsFragment;
import com.definesys.smecrailtransit.module.lineCharts.Fragment.MonthFragment;

import java.util.ArrayList;

/**
 * Created by xupeizuo on 2018/3/5.
 */
public class LineChartsActivity extends SmecBaseFragment<LineChartsPresenter> {

    private ActivityLineChartsBinding activityLineChartsBinding;
    private ArrayList<Fragment> fragments=new ArrayList<>();
    private int currentFrgment=0;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activityLineChartsBinding=DataBindingUtil.inflate(inflater,R.layout.activity_line_charts,container,false);
        initView();
        return activityLineChartsBinding.getRoot();
    }

    @Override
    protected LineChartsPresenter getPersenter() {
        return new LineChartsPresenter(getActivity());
    }


    private void initView(){
        fragments.add(DayChartsFragment.newInstance());
        fragments.add(MonthFragment.newInstance());
        activityLineChartsBinding.viewPage.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });
        activityLineChartsBinding.viewPage.setCurrentItem(currentFrgment);
        activityLineChartsBinding.smecDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activityLineChartsBinding.viewPage.setCurrentItem(0);
                activityLineChartsBinding.invalidateAll();
            }
        });
        activityLineChartsBinding.smecMonth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activityLineChartsBinding.viewPage.setCurrentItem(1);
                activityLineChartsBinding.invalidateAll();
            }
        });
    }


    public static LineChartsActivity newInstance() {
        Bundle args = new Bundle();
        LineChartsActivity fragment = new LineChartsActivity();
        fragment.setArguments(args);
        return fragment;
    }
}
